//
//  NMPOFuncIpCell.swift
//  NMPO
//
//  Created by PowerfullClean on 2023/10/31.
//

import UIKit

class NMPOFuncIpCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.addSubview(nmpo_bottomView)
        contentView.addSubview(nmpo_titleLabel)
        contentView.addSubview(nmpo_arrowView)
        contentView.addSubview(nmpo_cityView)
        contentView.addSubview(nmpo_regionView)
        contentView.addSubview(nmpo_countryView)
        nmpo_bottomView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        nmpo_titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(24)
            make.left.equalToSuperview().offset(18)
        }
        nmpo_arrowView.snp.makeConstraints { make in
            make.centerY.equalTo(nmpo_titleLabel.snp.centerY)
            make.right.equalToSuperview().offset(-20)
            make.size.equalTo(CGSize(width: 19, height: 10))
        }
        nmpo_regionView.snp.makeConstraints { make in
            make.width.equalTo((nmpo_SCREEN_WIDTH-40)/3.0)
            make.left.equalToSuperview()
            make.bottom.equalToSuperview().offset(-20)
            make.height.equalTo(42)
        }
        nmpo_cityView.snp.makeConstraints { make in
            make.width.equalTo((nmpo_SCREEN_WIDTH-40)/3.0)
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-20)
            make.height.equalTo(42)
        }
        nmpo_countryView.snp.makeConstraints { make in
            make.width.equalTo((nmpo_SCREEN_WIDTH-40)/3.0)
            make.right.equalToSuperview()
            make.bottom.equalToSuperview().offset(-20)
            make.height.equalTo(42)
        }
        NotificationCenter.default.addObserver(forName: nmpo_funIPINFOUpdate_noti, object: nil, queue: OperationQueue.main) { nmpo_noti in
            if let nmpo_model = nmpo_noti.object as? NMPOIPScanModel {
                self.nmpo_cityView.nmpo_valueLabel.text = nmpo_model.nmpo_city
                self.nmpo_regionView.nmpo_valueLabel.text = nmpo_model.nmpo_region
                self.nmpo_countryView.nmpo_valueLabel.text = nmpo_model.nmpo_country
            }
        }
        if let nmpo_funcInModel = NMPOManager.nmpo_manager.nmpo_funcInModel {
            self.nmpo_cityView.nmpo_valueLabel.text = nmpo_funcInModel.nmpo_city
            self.nmpo_regionView.nmpo_valueLabel.text = nmpo_funcInModel.nmpo_region
            self.nmpo_countryView.nmpo_valueLabel.text = nmpo_funcInModel.nmpo_country
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: - nmpo lazy
    lazy var nmpo_bottomView: UIImageView = {
        let nmpo_bottomView = UIImageView(image: UIImage(named: "nmpo_func_ip"))
        return nmpo_bottomView
    }()
    lazy var nmpo_titleLabel: UILabel = {
        let nmpo_titleLabel = UILabel()
        nmpo_titleLabel.font = UIFont.systemFont(ofSize: 16)
        nmpo_titleLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
        nmpo_titleLabel.text = "Your IP information"
        return nmpo_titleLabel
    }()

    lazy var nmpo_arrowView: UIImageView = {
        let nmpo_arrowView = UIImageView(image: UIImage(named: "nmpo_func_ipArrpw"))
        return nmpo_arrowView
    }()
    lazy var nmpo_regionView: NMPOFuncIpItemItemView = {
        let nmpo_regionView = NMPOFuncIpItemItemView()
        return nmpo_regionView
    }()
    lazy var nmpo_cityView: NMPOFuncIpItemItemView = {
        let nmpo_cityView = NMPOFuncIpItemItemView()
        nmpo_cityView.nmpo_titleLabel.text = "City"
        return nmpo_cityView
    }()
    lazy var nmpo_countryView: NMPOFuncIpItemItemView = {
        let nmpo_countryView = NMPOFuncIpItemItemView()
        nmpo_countryView.nmpo_titleLabel.text = "Country"
        return nmpo_countryView
    }()
}

class NMPOFuncIpItemItemView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(nmpo_titleLabel)
        addSubview(nmpo_valueLabel)
        nmpo_titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview()
           
        }
        nmpo_valueLabel.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.centerX.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var nmpo_titleLabel: UILabel = {
        let nmpo_titleLabel = UILabel()
        nmpo_titleLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xDA9579)
        nmpo_titleLabel.font = UIFont.systemFont(ofSize: 12)
        nmpo_titleLabel.text = "Region"
        return nmpo_titleLabel
    }()
    lazy var nmpo_valueLabel: UILabel = {
        let nmpo_valueLabel = UILabel()
        nmpo_valueLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
        nmpo_valueLabel.font = UIFont.systemFont(ofSize: 14)
        nmpo_valueLabel.text = "-"
        return nmpo_valueLabel
    }()
}
